import axios from "axios";

export default {
  login(username, password) {
    return axios
      .post("/users/login", {
        username,
        password,
      })
      .then(function (response) {
        return response.data;
      })
      .catch(function (error) {
        console.log(error);
      });
  },
  check(username) {
    return axios
      .get("/users/check", {
        params: {
          username,
        },
      })
      .then(function (response) {
        return response.data;
      });
  },
  reg(username, password) {
    return axios
      .post("/users/reg", {
        username,
        password,
        role: true,
      })
      .then(function (response) {
        return response.data;
      })
      .catch(function (error) {
        console.log(error);
      });
  },
  get(curPage, eachPage) {
    return axios
      .get("/users/getMsg", {
        params: {
          curPage,
          eachPage,
        },
      })
      .then(function (response) {
        return response.data;
      });
  },
  updateUser(id, phone, address) {
    return axios
      .post("/users/updateUser", {
        id,
        phone,
        address,
      })
      .then(function (response) {
        return response.data;
      })
      .catch(function (error) {
        console.log(error);
      });
  },
  addUser({ username, password, role, address, phone }) {
    return axios
      .post("/users/addUser", {
        username,
        password,
        role,
        address,
        phone,
      })
      .then(function (response) {
        return response.data;
      })
      .catch(function (error) {
        console.log(error);
      });
  },
  searchUser(username, curPage, eachPage) {
    return axios
      .get("/users/searchUser", {
        params: {
          username,
          curPage,
          eachPage,
        },
      })
      .then(function (response) {
        return response.data;
      });
  },
};
